<?php $this->load->view('common/head'); ?>

<?php $this->load->view('common/header'); ?>
<style>
    .extra_info {
        display: none;
    }
</style>
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <?php $this->load->view('common/sidebar'); ?>
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <?php $this->load->view('common/breadcrumbs'); ?>

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">

                <?php $this->load->view('common/set'); ?>
                <div class="row">
                    <div class="col-sm-22 widget-container-col ui-sortable" id="widget-container-col-10">
                        <div class="tab-pane">
                            <div class="col-xs-12">
                                <!-- PAGE CONTENT BEGINS -->
                                <form class="form-horizontal" action="<?php echo site_url(X_URL . 'article/update'); ?>"
                                      method="post" id="from1">
                                    <?php echo csrf_hidden(); ?>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label no-padding-right" for="form-field-6">
                                            选择分类 </label>
                                        <div class="col-sm-9">
                                            <select id="category" name="category"
                                                    class="col-xs-10 col-sm-10 select2">
                                                <option value="">可选择</option>
                                                <?php if (isset($category)) { ?>
                                                    <?php foreach ($category as $key => $val) { ?>
                                                        <option value="<?php echo $val['id']; ?>"
                                                                <?php if (isset($article) && $article['category'] == $val['id']){ ?>selected="selected"<?php } ?> ><?php echo $val['category_name']; ?>
                                                        </option>
                                                    <?php } ?>
                                                <?php } ?>
                                            </select>
                                        </div>
                                    </div>
                                    <input type="hidden" name="article_id" value="<?php if (isset($article)) {
                                        echo $article['id'];
                                    } ?>">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label no-padding-right" for="form-field-1">
                                            产品标题 </label>
                                        <div class="col-sm-9">
                                            <input type="text" id="title" name="title" class="col-xs-10 col-sm-10"
                                                   value="<?php if (isset($article)) {
                                                       echo $article["title"];
                                                   } ?>">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label no-padding-right" for="form-field-4">
                                            图片上传 </label>
                                        <div class="col-sm-9">
                                            <input id="kv-explorer" class="col-xs-10 col-sm-5" name="file[]" type="file"
                                                   accept="image/*" multiple>
                                        </div>
                                    </div>
                                    <input type="hidden" id="access_key" name="access_key"
                                           value="<?php if (!empty($article['access_key'])) {
                                               echo $article['access_key'];
                                           } ?>">
                                    <div class="space-4"></div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label no-padding-right" for="form-field-8">
                                            产品详情 </label>
                                        <div class="col-sm-9">
                                            <textarea name="content" id="content"
                                                      style="width:85%;height:400px;visibility:hidden;"><?php if (!empty($article['content'])) {
                                                    echo $article['content'];
                                                } ?></textarea>
                                        </div>
                                    </div>
                                    <div class="space-4"></div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label no-padding-right" for="form-field-2">
                                            是否热销 </label>
                                        <div class="col-sm-9">
                                            <input name="is_hot" id="is_hot"
                                                   <?php if (!empty($article) && $article['is_hot'] == 1){ ?>checked="checked"<?php } ?>
                                                   value="1" class="ace ace-switch ace-switch-5" type="checkbox"/>
                                            <span class="lbl"></span>
                                        </div>
                                        <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle"></span>
										</span>
                                    </div>
                                    <div class="col-md-offset-2 col-md-9">
                                        <button class="btn btn-info" type="button" id="subForm1">
                                            <i class="icon-ok bigger-110"></i>
                                            提交
                                        </button>

                                        &nbsp; &nbsp; &nbsp;
                                        <button class="btn" type="reset">
                                            <i class="icon-undo bigger-110"></i>
                                            重置
                                        </button>
                                    </div>
                                </form>
                                <!-- PAGE CONTENT ENDS -->
                            </div><!-- /.col -->
                        </div>


                    </div>
                </div>
                <!-- /section:settings.box -->
                <div class="row">

                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
</div><?php $this->load->view('common/footer'); ?>


<?php $this->load->view('common/footerjs'); ?>
<!-- inline scripts related to this page -->
<script type="text/javascript">
    $(function () {
        var article_category = "<?php if (isset($article)) {
            echo $article["category"];
        } else {
            echo 0;
        } ?>";

        if (article_category == 10) {
            $(".extra_info").show();
        }
        $("#tabs").tabs();
        var editor = KindEditor.create('textarea[name="content"]', {
            uploadJson: baseurl + 'index.php/Upload/editor_upload_img?type=article',
            fileManagerJson: '__PUBLIC__/kindeditor/php/file_manager_json.php',
            allowFileManager: true,
            urlType: 'domain',
            afterBlur: function () {
                this.sync();
            }
        });
        var picpath = <?php echo $pic_path;?>;
        var piccon = <?php echo $pic_con;?>;
        $(document).ready(function () {
            $("#kv-explorer").fileinput({
                language: 'zh',
                uploadAsync: false, //设置上传同步异步 此为同步
                showRemove: false,
                showCaption: false,
                dropZoneEnabled: false,
                'theme': 'explorer-fa',
                'uploadUrl': baseurl + 'index.php/Upload/upload_batch?type=product',
                overwriteInitial: false,
                initialPreviewAsData: true,
                initialPreviewFileType: 'image',
                initialPreview: picpath, //要显示的图片的路径
                initialPreviewConfig: piccon
            });
            $("#kv-explorer").on("filebatchuploadsuccess", function (event, data) {
                var rst = data.response;
                var access_key = rst.access_key;
                $("#access_key").val(access_key);
            });


        });
        $("#subForm1").click(function () {
            var title = $("#title").val();
            var category = $("#category").val();
            if (title == '') {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "产品标题必须填写。",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return;
            }
            if (category == '') {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "所属车型必须选择。",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return;
            }
            if (title.length > 26) {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "标题不能大于26个字符。",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return;
            }
            $("#from1").submit();
        });

        // 选项切换效果
        $(".select2").select2();

        $("#category").on("select2:select", function (e) {
            console.log($(this).val());
            if ($(this).val() == 10) {
                $(".extra_info").fadeIn();
            } else {
                $(".extra_info").fadeOut();
            }
        });

    });

</script>
</body>
</html>
